#include"colorblock.h"
#include<QColorDialog>
ColorBlock::ColorBlock(QPushButton *parent, int id, int size):
    QPushButton(parent),
    id(id)
{
    this->setFixedSize(size,size);
    connect(this,SIGNAL(pressed()),this,SLOT(setId()));

}
void ColorBlock::setColor(const QColor &color)
{
    this->color=color;
    //QString qss = QString("background-color: %1").arg(this->color.name());
    QString qss = QString("border-color: #000;border-width: 4px;border-style: solid;background-color: %1").arg(this->color.name());
    this->setStyleSheet(qss);
    emit sendColor(this->color);
    //改变center数组
    emit sendColorAndId(color,this->id);
}
void ColorBlock::setFocused(bool isFocus)
{
    if(isFocus)
    {
        QString qss = QString("border-color: #000;border-width: 4px;border-style: solid;background-color: %1").arg(this->color.name());
        this->setStyleSheet(qss);
    }
    else
    {
        QString qss = QString("border-color: #000;border-width: 0px;border-style: solid;;background-color: %1").arg(this->color.name());
        this->setStyleSheet(qss);
    }
}
void ColorBlock::setId()
{
    emit sendId(this->id);
}

